<template>
    <!-- pages/openkf/openkf.wxml -->
    <view class="button-sp-area">
        <button class="bottom" type="primary" @tap="openkf">点击联系客服</button>
		<private_tip :privateShow="privateb"></private_tip>
    </view>
</template>

<script>
//获取应用实例
const app = getApp();
export default {
    data() {
        return {
			privateb:false,
		};
    },
    onLoad: function (options) {
		let _this=this;
		if(app.globalData.wxprivate==-1){
			app.watchG('wxprivate',function(value){
				_this.wxprivate=value;
				if(value){ //弹出弹窗
					_this.privateb=true;
				}else{
					_this.onload(options);
				}
			})
		}else{
			if (app.globalData.wxprivate) { //弹出弹窗
				_this.privateb = true;
			} else {
				_this.onload(options);
			}
		}
    },
	onShareAppMessage(res) {
		let config=app.globalData.appConfig;
		return {
			title: config.share.title,
			desc:config.share.description,
			path:'/pages/index/index',
			imageUrl:app.globalData.masterDomain+'/include/json.php?action=getSystemLogo'
		};
	},
	// 分享到朋友圈
	onShareTimeline() {
		return {
			title: config.share.title,
			imageUrl:app.globalData.masterDomain+'/include/json.php?action=getSystemLogo'
		};
	},
    methods: {
		onload(options){
			this.url = options && options.url ? decodeURIComponent(options.url) : '';
			this.corpId = options && options.id ? options.id : '';
		},
        openkf: function (e) {
            if (this.url && this.corpId) {
                uni.openCustomerServiceChat({
                    extInfo: {
                        url: this.url
                    },
                    corpId: this.corpId,
                    success(res) {
                        console.log(res);
                    }
                });
            } else {
                if (this.url) {
                    uni.navigateTo({
                        url: '/pages/redirect/index?url=' + encodeURIComponent(this.url)
                    });
                } else {
                    uni.showToast({
                        title: '客服链接获取失败',
                        icon: 'none',
                        duration: 2000
                    });
                    setTimeout(function () {
                        uni.navigateBack({
                            delta: 1
                        });
                    }, 2000);
                }
            }
        }
    }
};
</script>
<style>
@import './openkf.css';
</style>
